<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <script src="./js/earthsdk.js"></script>
    <!-- 自定义Css样式 -->
    <link rel="stylesheet" href="./css/example1.css">
    <title>Cesium地球初始化</title>
    <style>
        html,
        body,
        #app {
            width: 100%;
            height: 100%;
            margin: 0px;
            padding: 0px;
        }

        .box {
            display: grid;
            grid-template-columns: 80px 1fr;
        }

        .btn {
            display: flex;
            padding-top: 10px;
        }
    </style>
</head>

<body>
    <div id="app"></div>

    <div id="panel">
        <p>位置信息</p>
        <div class="box">
            <label for="">经度</label> <input id="lon" type="number" value="120.26895628709843">
            <label for="">纬度</label> <input id="lat" type="number" value="31.99890350891649">
            <label for="">高度</label> <input id="height" type="number" value="1269.9201196285085">
        </div>
        <p>姿态信息</p>
        <div class="box">
            <label for="">偏航角</label> <input id="yaw" type="number" value="333.4666903019263">
            <label for="">俯仰角</label> <input id="pitch" type="number" value="-44.392623459065334">
            <label for="">转滚角</label> <input id="roll" type="number" value="0.0027997885275428858">
        </div>
        <div class="btn">
            <button onclick="getCurrentCameraInfo()">获取当前视角信息</button>
            <button onclick="flyIn()">当前参数飞入</button>
        </div>
    </div>
    <script>
        /** ---------------------------------地球创建------------------------------------**/
        // Vue中引入方式：import { ESObjectsManager } from 'earthsdk3';
        const { ESObjectsManager } = window['EarthSDK3']
        const { ESCesiumViewer } = window['EarthSDK3_Cesium']
        const { ESUeViewer } = window['EarthSDK3_UE']

        const objm = new ESObjectsManager(ESCesiumViewer, ESUeViewer);
        window.g_objm = objm;

        // 通过json创建一个影像图层
        const imageryLayer = objm.createSceneObjectFromJson({
            "id": "9812a65f-0de0-4f7b-b234-809c0c2fb8ef",
            "type": "ESImageryLayer",
            "maximumLevel": 16,
            "url": "https://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"
        });

        /** --------------------------飞行定位----------------------------------**/

        // 飞到初始位置
        function flyIn() {
            const lon = Number(document.getElementById("lon").value)
            const lat = Number(document.getElementById("lat").value)
            const height = Number(document.getElementById("height").value)
            const yaw = Number(document.getElementById("yaw").value)
            const pitch = Number(document.getElementById("pitch").value)
            const roll = Number(document.getElementById("roll").value)

            objm.activeViewer.flyIn([lon, lat, height], [yaw, pitch, roll], 3)
        }

        /** --------------------------获取当前视角信息----------------------------------**/
        // 获取当前视角信息
        function getCurrentCameraInfo() {
            const view = objm.activeViewer.getCurrentCameraInfo()
            if (!view) {
                alert("获取当前视角为空")
                return
            }
            const { position, rotation } = view
            document.getElementById("lon").value = position[0]
            document.getElementById("lat").value = position[1]
            document.getElementById("height").value = position[2]
            document.getElementById("yaw").value = rotation[0]
            document.getElementById("pitch").value = rotation[1]
            document.getElementById("roll").value = rotation[2]
        }



        // 监听视口创建完成事件
        objm.viewerCreatedEvent.don((viewer) => { flyIn() })
        // 创建Cesium视口
        const viewer = objm.createCesiumViewer({
            type: 'ESCesiumViewer',
            container: document.getElementById("app"),
        });

    </script>

    <!-- 切换UE和Cesium引擎的组件（Vue） -->
    <div id="root">
        <switch-engine :objm="objm"></switch-engine>
    </div>
    <!-- Vue文件 -->
    <script src="./js/vue.global.js"></script>
    <!-- 切换UE和Cesium的组件 -->
    <script src="./js/switchEngineCom.js"></script>
</body>

</html>